package edu.xjnu.uitls;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2Config {
    @Bean
    public Docket webApiConfig() {
        return new Docket(DocumentationType.SPRING_WEB)
                .groupName("webApi")
                .apiInfo(webApiInfo())
                .select()
                //复制进来只需要改一个 就是这个路径 和你的controller 路径相匹配
                //如果匹配 就可以自动识别 你的 controller 路径
                .paths(Predicates.not(PathSelectors.regex("/controller/.*")))
                // .paths(Predicates.not(PathSelectors.regex("*.*")))
                .build();
    }


    public Docket adminApiConfig() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("adminApi")
                .apiInfo(adminApiInfo())
                .select()
                //同上也需要改
                .paths(Predicates.and(PathSelectors.regex("/controller/.*")))
                .build();
    }

    //接口的信息
    private ApiInfo webApiInfo() {
        return new ApiInfoBuilder()
                .title("网站-进行Swagger-ui的测试")
                .description("学习Swagger用来接口api文档 测试 ")
                .version("1.0")
                .build();
    }

    private ApiInfo adminApiInfo() {
        return new ApiInfoBuilder()
                .title("网站-Swagger-ui测试")
                .description("本文档用来学习Swagger 接口api文档 测试")
                .version("1.0")
                .build();
    }
}